from PyQt5.QtGui import QColor

class StyleManager:
    """统一管理应用程序样式"""

    # 定义主题
    THEMES = {
        "light": {  # 浅色主题
            "background": "#F8F8FF",
            "text": "#000000",  # 确保为黑色
            "button": "#008B8B",
            "table": "white",
            "log": "#f0f0f0"
        },
        "dark": {   # 深色主题
            "background": "#2d2d2d",
            "text": "#ffffff",  # 白色
            "button": "#DAA520",
            "table": "#1e1e1e",
            "log": "#f0f0f0"
        },
        "eye_care": {  # 护眼主题
            "background": "#e8f4ea",
            "text": "#000000",  # 确保为黑色
            "button": "#d4e8d4",
            "table": "#f0f7f0",
            "log": "#e0eee0"
        }
    }

    @classmethod
    def get_theme(cls, theme_name):
        """获取主题配置"""
        return cls.THEMES.get(theme_name, cls.THEMES["light"])

    @classmethod
    def get_style(cls, component, theme_name):
        """获取组件样式"""
        theme = cls.get_theme(theme_name)

        styles = {
            "main_window": f"background-color: {theme['background']};",
            "button": f"""
                QPushButton {{
                    color: {theme['text']};
                    background-color: {theme['button']};
                    border: 1px solid {theme['text']};
                    padding: 3px;
                    min-width: 50px;
                }}
                QPushButton:hover {{
                    background-color: {theme['button']};
                    opacity: 0.8;
                }}
                QPushButton:pressed {{
                    background-color: {theme['button']};
                    opacity: 0.6;
                }}
                QPushButton:disabled {{
                    color: {theme['text']};
                    opacity: 0.5;
                }}
            """,
            "table": f"""
                QTableWidget {{
                    background-color: {theme['table']};
                    color: {theme['text']};
                    gridline-color: {theme['text']};
                }}
                QHeaderView::section {{
                    background-color: {theme['button']};
                    color: {theme['text']};
                    padding: 5px;
                    border: 1px solid {theme['text']};
                }}
            """,
            # "upload_group": f"""
            #     QGroupBox#upload_group {{
            #         color: {theme['text']} !important;
            #     }}
            #     QGroupBox#upload_group::title {{
            #         color: {theme['text']} !important;
            #         margin-left: 10px;
            #     }}
            # """
            "upload_group": f"""
                QGroupBox#uploadContainer {{
                    border: 1px solid gray;
                    margin-top: 10px;
                    padding-top: 15px;
                    color: {theme['text']} !important;
                }}
                QGroupBox#uploadContainer::title {{
                    color: {theme['text']} !important;
                    subcontrol-origin: margin !important;
                    left: 10px !important;
                    background-color: transparent !important;
                }}
            """,
            "settings_group": f"""
                QGroupBox#settingsContainer {{
                    border: 1px solid gray;
                    margin-top: 20px;
                    padding-top: 15px;
                    color: {theme['text']} !important;
                }}
                QGroupBox#settingsContainer::title {{
                    color: {theme['text']} !important;
                    subcontrol-origin: margin !important;
                    left: 10px !important;
                    background-color: transparent !important;
                }}
            """,
            "input_fields": f"""
                QSpinBox, QLineEdit {{
                    color: {theme['text']} !important;
                    background-color: {theme['background']} !important;
                    border: 1px solid {theme['text']} !important;
                    padding: 5px !important;
                    font-size: 14px !important;
                }}
            """
        }

        return styles.get(component, "")